<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('basic');
	$return['list']=array();
	set_html('title','核销台');
	$mid = $_SESSION['uid'];
	$uniacd = $_SESSION['uniacid'];
	$merchid = 0;
	//$merch_plugin = p('merch');
	$saler = pdo_fetch('select * from ' . tablename('jy_weishop_store_worker') . ' where mid=:mid and uniacid=:uniacid limit 1', array(':uniacid' => $_SESSION['uniacid'], ':mid' => $mid));
		if (empty($saler) && $merch_plugin) 
		{
			$saler = pdo_fetch('select * from ' . tablename('jy_weishop_store_worker') . ' where mid=:mid and uniacid=:uniacid limit 1', array(':uniacid' => $_SESSION['uniacid'], ':mid' => $mid));
		}
		if (empty($saler)) 
		{
			//exi('您无核销权限!','error');
		}
		else 
		{
			$merchid = $saler['merchid'];
		}
		$member =pdo_get('core_members',array('uniacid'=>$uniacid,'id'=>$mid));
		$store = false;
		if (!(empty($saler['storeid']))) 
		{
			if (0 < $merchid) 
			{
				$store = pdo_fetch('select * from ' . tablename('jy_weishop_store') . ' where id=:id and uniacid=:uniacid and merchid = :merchid limit 1', array(':id' => $saler['storeid'], ':uniacid' => $_SESSION['uniacid'], ':merchid' => $merchid));
			}
			else 
			{
				$store = pdo_fetch('select * from ' . tablename('jy_weishop_store') . ' where id=:id and uniacid=:uniacid limit 1', array(':id' => $saler['storeid'], ':uniacid' => $_SESSION['uniacid']));
			}
		}
	$return['saler']=$saler;
	$return['store']=$store;
	$return['member']=$member;
	exi($return);
}
if($_RQ['op']=='search'){
	$post=get_postdata();
	$verifycode = trim($post['verifycode']);
	if (empty($verifycode)) 
		{
			exi('请填写消费码或自提码','error');
		}
		$orderid = pdo_fetchcolumn('select id from ' . tablename('jy_weishop_order') . ' where uniacid=:uniacid and ( verifycode=:verifycode or verifycodes like :verifycodes ) limit 1 ', array(':uniacid' => $_SESSION['uniacid'], ':verifycode' => $verifycode, ':verifycodes' => '%|' . $verifycode . '|%'));
		$order=pdo_get('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$orderid));
		if (empty($orderid)) 
		{
			exi('未查询到订单,请核对','error');
		}
		/*
		$allow = com('verify')->allow($orderid);
		if (is_error($allow)) 
		{
			exi($allow['message'],'error');
		}
		extract($allow);
		$verifyinfo = iunserializer($order['verifyinfo']);
		*/
		$verifyinfo=$order['verifyinfo'];
		if ($order['verifytype'] == 2) 
		{
			foreach ($verifyinfo as &$v ) 
			{
				unset($v['select']);
				if ($v['verifycode'] == $verifycode) 
				{
					if ($v['verified']) 
					{
						exi('此消费码已经使用!','error');
					}
					$v['select'] = 1;
				}
			}
			unset($v);
			pdo_update('jy_weishop_order', array('verifyinfo' => $verifyinfo), array('id' => $orderid));
		}
			
		$return['order']=$order;
		print($order);exit;
		exi($return);
	
}
	
?>